﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace FreeSwitch.EventSocket.Events
{
	class EventTypeLoader
	{

		public static void ScanForEvents(Assembly assembly, Action<string, Type> foundAction)
		{
			Type eventType = typeof(Event);
			foreach (Type type in assembly.GetTypes())
			{
				if (type.IsAbstract || type.IsInterface || !eventType.IsAssignableFrom(type))
					continue;

				object[] attributes = type.GetCustomAttributes(typeof(EventNameAttribute), false);
				if (attributes == null || attributes.Length == 0)
					continue;

				foreach (EventNameAttribute attribute in attributes)
					foundAction(attribute.Name, type);
			}
		}
	}
}
